package com.yangzb.java.sample.lock;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class LockTest {
    private static final long KEEP_ALIVE_TIME = 10L;
    private static final TimeUnit UNIT = TimeUnit.MINUTES;
    private static final BlockingQueue<Runnable> WORK_QUEUE = new LinkedBlockingQueue<>(100000000);
    private static final ThreadPoolExecutor.CallerRunsPolicy HANDLER = new ThreadPoolExecutor.CallerRunsPolicy();
    private static final int CORE_POOL_SIZE = 2;
    private static final int MAXIMUM_POOL_SIZE = 200;
    private static ThreadPoolExecutor THREAD_POOL_EXECUTOR_VALIDATE = new ThreadPoolExecutor(CORE_POOL_SIZE,
            MAXIMUM_POOL_SIZE,
            KEEP_ALIVE_TIME,
            UNIT,
            WORK_QUEUE,
            HANDLER);
    public static void main(String[] args) {
        LockObject lockObject = new LockObject();
        LockObject lockObject2 = new LockObject();

        THREAD_POOL_EXECUTOR_VALIDATE.submit(() -> {
            lockObject.test1();
        });
        THREAD_POOL_EXECUTOR_VALIDATE.submit(() -> {
            lockObject2.test2();
        });
    }
}
